package cn.cnsuh.q121_maxProfit;

/**
 * created by mzk on 2020/07/18
 */
public class Main {
    public static void main(String[] args) {
        int[] prices = {7,1,5,3,6,4};

        System.out.println(maxProfit(prices));

    }
    static int maxProfit(int[] prices) {
        int max = 0;
        int min = Integer.MAX_VALUE;
        for(int i = 0 ; i < prices.length ; i++){
            if(prices[i] < min){
                min = prices[i];
            }

            if(prices[i] - min > max){
                max = prices[i] - min;
            }
        }
        return max;
    }

}
